package com.zhou.common.mybatis.template.shiro.config.shiro;

import com.zhou.common.lib.core.text.CharsetKit;
import org.apache.shiro.crypto.AesCipherService;
import org.apache.shiro.mgt.AbstractRememberMeManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.subject.SubjectContext;

import java.security.Key;
import java.util.Base64;

public class CustomRememberMeService extends AbstractRememberMeManager {

    /**
     * 删除 remember me id
     *
     * @param subject
     */
    @Override
    protected void forgetIdentity(Subject subject) {

    }

    /**
     * 保存 rememerMe 的id,以便通过id重新认证
     *
     * @param subject
     * @param serialized
     */
    @Override
    protected void rememberSerializedIdentity(Subject subject, byte[] serialized) {

    }

    /**
     * 获取 remember me id
     *
     * @param subjectContext
     * @return
     */
    @Override
    protected byte[] getRememberedSerializedIdentity(SubjectContext subjectContext) {
        return new byte[0];
    }


    /**
     * 删除 remember me id
     *
     * @param subjectContext
     */
    @Override
    public void forgetIdentity(SubjectContext subjectContext) {

    }

    public static void main(String[] args) {
        AesCipherService cipherService = new AesCipherService();
        Key key = cipherService.generateNewKey();
        String password = "123456";
        String key1 = "ab6fdeaaf26243bf";
        byte[] key2 = org.apache.shiro.codec.Base64.decode(key1);
        String s = cipherService.encrypt(password.getBytes(CharsetKit.CHARSET_UTF_8), key2).toBase64();

        byte[] bytes = cipherService.decrypt(Base64.getDecoder().decode(s), key2).getBytes();
        System.out.println(new String(bytes, CharsetKit.CHARSET_UTF_8));


    }
}
